package com.javawork.juc.synchronize;

/**
 * @author zhangxiaolu
 * @since 2023-02-16 0:10
 */
public class LockClearUPDemo {

    static Object objectLock = new Object();

    public void m1() {
        //锁消除问题，JIT编译器会无视它，每次都new出来的，不存在了，非正常的
        Object o = new Object();
        synchronized (o) {
            System.out.println("-----hello LockClearUPDemo" + "\t" + o.hashCode() + "\t" + objectLock.hashCode());
        }
    }

    public static void main(String[] args) {
        LockClearUPDemo lockClearUPDemo = new LockClearUPDemo();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                lockClearUPDemo.m1();
            }, String.valueOf(i)).start();
        }
    }
}
